<?php
session_start ();
// 判断用户是否已经登录
if (! isset ( $_SESSION ["userinfo"] ) and empty ( $_SESSION ["userinfo"] ["userid"] )) {
	session_unset ();
	session_destroy ();
	header ( "location:../index.php" );
	exit ();
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Language" content="zh-CN">
<link href="./Resource/Style/base.yy.css" rel="stylesheet"
	type="text/css">
<link href="./Resource/Style/info.yy.css" rel="stylesheet"
	type="text/css">
</head>
<body>
<?php
require_once '../tools/SqlHelper.class.php';
if (isset ( $_POST ['user_submit'] ) and $_POST ['user_submit'] == '保存') {
	// 获取浏览器发过来的页面数据
	$username = $_POST ['username'];
	$user_sex= $_POST ['user_sex'];
	$ps_qq = $_POST ['qq'];
	$ps_height = $_POST ['height'];
	$ps_blood_type = $_POST ['blood_type'];
	$ps_weight = $_POST ['weight'];
	$ps_profession = $_POST ['work'];
	$ps_education = $_POST ['edu'];
	$ps_marry_condition = $_POST ['marry_type'];
	$ps_birthplace = $_POST ['homeplaceProvinceId'];
	$ps_monthly_income = $_POST ['income'];
	$sel_ht_prov = $_POST ['sel_ht_prov'];
	$ps_is_house = $_POST ['have_house'];
	$ps_birthday_year = $_POST ['sel_year'];
	$ps_birthday_month = $_POST ['sel_month'];
	$ps_birthday_day = $_POST ['sel_day'];
	$ps_apartment = $_POST ['s_province'] . " " . $_POST ['s_city'] . " " . $_POST ['s_county'];
	$ps_apartment_str = preg_split ( "/[\s,]+/", $ps_apartment );
	
	$user_id = $_SESSION ["userinfo"] ["userid"];
	// $user_id = "xufeng520";
	$_SESSION ["userinfo"] ["username"] = $username;
	$sql = "UPDATE `user_tb` SET `user_name`='$username' WHERE `user_id`='$user_id'";
	// 创建一个SqlHelper对象
	$sqlHelper = new SqlHelper ();
	$res = $sqlHelper->execute_dql ( $sql );
	if (! $res) {
		echo "<script>alert('保存资料失败')</script>";
	}
	
	$sql = "UPDATE `personal_data_tb` SET `ps_qq`='$ps_qq', `ps_blood_type`='$ps_blood_type',
	`ps_profession`='$ps_profession', `ps_marry_condition`='$ps_marry_condition', `ps_birthplace`='$ps_birthplace',
	`ps_birthday_year`='$ps_birthday_year', `ps_birthday_month`='$ps_birthday_month',`ps_birthday_day`='$ps_birthday_day',`ps_height`='$ps_height', `ps_weight`='$ps_weight',
	`ps_education`='$ps_education', `ps_monthly_income`='$ps_monthly_income', `ps_apartment`='$ps_apartment',
	`ps_is_house`='$ps_is_house' WHERE `user_id`='$user_id'";
	$res = $sqlHelper->execute_dql ( $sql );
	if (! $res) {
		echo "<script>alert('保存资料失败')</script>";
	} else {
		echo "<script>alert('保存资料成功')</script>";
	}
	// 资源
	// mysql_free_result ( $res );
	// 关闭连接
	$sqlHelper->close_connect ();
	
	// echo "" . $nickName . $ps_qq . $ps_height . $ps_blood_type . $ps_weight . $ps_profession . $ps_education . $ps_marry_condition . $ps_birthplace . $ps_monthly_income . $sel_ht_prov . $ps_is_house . $ps_birthday . $ps_apartment . $spaceService;
} else {
	$user_id = $_SESSION ["userinfo"] ["userid"];
	$username = $_SESSION ["userinfo"] ["username"];
	// $username = "许峰";
	// $user_id = "xufeng520";
	
	$sql = "select * from `personal_data_tb` where `user_id`='$user_id'";
	// 创建一个SqlHelper对象
	$sqlHelper = new SqlHelper ();
	$row = $sqlHelper->execute_dql ( $sql );
	$res = mysql_fetch_array ( $row );
	// 关闭连接
	$ps_qq = $res ['ps_qq'];
	$user_sex = $res ['ps_sex'];
	if ($user_sex == "0") {
		$user_sex = "男";
	} else {
		$user_sex = "女";
	}
	$ps_height = $res ['ps_height'];
	$ps_blood_type = $res ['ps_blood_type'];
	$ps_weight = $res ['ps_weight'];
	$ps_profession = $res ['ps_profession'];
	$ps_education = $res ['ps_education'];
	$ps_marry_condition = $res ['ps_marry_condition'];
	$ps_birthplace = $res ['ps_birthplace'];
	$ps_monthly_income = $res ['ps_monthly_income'];
	$sel_ht_prov = $res ['sel_ht_prov'];
	$ps_is_house = $res ['ps_is_house'];
	$ps_birthday_year = $res ['ps_birthday_year'];
	$ps_birthday_month = $res ['ps_birthday_month'];
	$ps_birthday_day = $res ['ps_birthday_day'];
	$ps_apartment = $res ['ps_apartment'];
	if ($ps_apartment == "0") {
		$ps_apartment = "省份 地级市 市、县级市";
	}
	$ps_apartment_str = preg_split ( "/[\s,]+/", $ps_apartment );
	mysql_free_result ( $row );
	$sqlHelper->close_connect ();
}
?>
		<nav>
		<div class="info_nav">
			<ul>
				<li><a class="a_out" href="#">基本资料</a></li>
				<li><a href="./Details.php">详细资料</a></li>
				<li><a href="./soliloquy.php">内心独白</a></li>
				<li><a href="./uploadingPhoto.php">上传头像</a></li>
				<li><a href="./myPhoto.php">我的相册</a></li>
				<li><a href="./PersonalCondition.php">征友条件</a></li>
				<li><a href="./changePassword.php">修改密码</a></li>
			</ul>
		</div>
	</nav>
	<form name="baseInfoForm" id="baseInfoForm" action="./baseData.php"
		method="post">
		<input type="hidden" name="user_sex" value="<?php echo $user_sex;?>"></input>
		<div class="info_con">
			<ol>
				<li class="li_big"><label>登录账号：</label> <span><?php echo $user_id;?></span></li>
				<li><label>昵称：</label> <input type="text"
					value="<?php echo $username;?>" name="username" maxlength="7"
					id="nickName"></li>
				<li><label>性别：</label> <font><?php echo $user_sex;?></font></li>
				<li><label>QQ号码：</label> <input id="qq" name="qq" maxlength="13"
					type="text" value="<?php echo $ps_qq;?>"></li>
				<li><label>身高：</label> <select id="height" name="height">
				<?php
				for($i = 140; $i < 200; $i ++) {
					if ($i == ( int ) $ps_height) {
						echo "<option class='selectList' value='" . $i . "' selected='true'>" . $i . "厘米</option>";
					} else {
						echo "<option class='selectList' value='" . $i . "'>" . $i . "厘米</option>";
					}
				}
				?>
				</select></li>
				<li><label>血型：</label> <select id="sel_blood" name="blood_type">
						<option class="selectList" value="0"
							<?php if($ps_blood_type == "0"){echo "selected='true'";}?>>未知</option>
						<option class="selectList" value="1"
							<?php if($ps_blood_type == "1"){echo "selected='true'";}?>>A</option>
						<option class="selectList" value="2"
							<?php if($ps_blood_type == "2")echo "selected='true'";?>>B</option>
						<option class="selectList" value="3"
							<?php if($ps_blood_type == "3")echo "selected='true'";?>>AB</option>
						<option class="selectList" value="4"
							<?php if($ps_blood_type == "4")echo "selected='true'";?>>O</option>
				</select></li>
				<li><label>体重：</label> <select id="weight" name="weight">
				<?php
				for($i = 7; $i < 21; $i ++) {
					if ($i == ( int ) $ps_weight / 10) {
						echo "<option class='selectList' value='" . $i * 10 . "' selected='true'>" . $i * 10 . "斤</option>";
					} else {
						echo "<option class='selectList' value='" . $i * 10 . "'>" . $i * 10 . "斤</option>";
					}
				}
				?>
				</select></li>
				<li><label>职业：</label> <select id="sel_work" name="work">
						<option class="selectList" value="0"
							<?php if($ps_profession == "0"){echo "selected='true'";}?>>未填写</option>
						<option class="selectList" value="1"
							<?php if($ps_profession == "1"){echo "selected='true'";}?>>在校学生</option>
						<option class="selectList" value="2"
							<?php if($ps_profession == "2"){echo "selected='true'";}?>>军人</option>
						<option class="selectList" value="3"
							<?php if($ps_profession == "3"){echo "selected='true'";}?>>私营业主</option>
						<option class="selectList" value="4"
							<?php if($ps_profession == "4"){echo "selected='true'";}?>>企业职工</option>
						<option class="selectList" value="5"
							<?php if($ps_profession == "5"){echo "selected='true'";}?>>农业劳动者</option>
						<option class="selectList" value="6"
							<?php if($ps_profession == "6"){echo "selected='true'";}?>>政府机关/事业单位工作者</option>
						<option class="selectList" value="7"
							<?php if($ps_profession == "7"){echo "selected='true'";}?>>其他</option>
				</select></li>
				<li><label>学历：</label> <select id="sel_edu" name="edu">
						<option class="selectList" value="0"
							<?php if($ps_education == "0"){echo "selected='true'";}?>>未填写</option>
						<option class="selectList" value="5"
							<?php if($ps_education == "5"){echo "selected='true'";}?>>初中及以下</option>
						<option class="selectList" value="1"
							<?php if($ps_education == "1"){echo "selected='true'";}?>>高中及中专</option>
						<option class="selectList" value="2"
							<?php if($ps_education == "2"){echo "selected='true'";}?>>大专</option>
						<option class="selectList" value="3"
							<?php if($ps_education == "3"){echo "selected='true'";}?>>本科</option>
						<option class="selectList" value="4"
							<?php if($ps_education == "4"){echo "selected='true'";}?>>硕士及以上</option>
				</select></li>
				<li><label>婚姻状况：</label> <select id="sel_marriage" name="marry_type">
						<option class="selectList" value="0"
							<?php if($ps_marry_condition == "0"){echo "selected='true'";}?>>未填写</option>
						<option class="selectList" value="1"
							<?php if($ps_marry_condition == "1"){echo "selected='true'";}?>>未婚</option>
						<option class="selectList" value="2"
							<?php if($ps_marry_condition == "2"){echo "selected='true'";}?>>离异</option>
						<option class="selectList" value="3"
							<?php if($ps_marry_condition == "3"){echo "selected='true'";}?>>丧偶</option>
				</select></li>
				<li><label class="wapce">月收入：</label> <select id="sel_salary"
					name="income">
						<option class="selectList" value="0"
							<?php if($ps_monthly_income == "0"){echo "selected='true'";}?>>未填写</option>
						<option class="selectList" value="3"
							<?php if($ps_monthly_income == "3"){echo "selected='true'";}?>>小于2000</option>
						<option class="selectList" value="4"
							<?php if($ps_monthly_income == "4"){echo "selected='true'";}?>>2000-5000</option>
						<option class="selectList" value="5"
							<?php if($ps_monthly_income == "5"){echo "selected='true'";}?>>5000-10000</option>
						<option class="selectList" value="6"
							<?php if($ps_monthly_income == "6"){echo "selected='true'";}?>>10000-20000</option>
						<option class="selectList" value="7"
							<?php if($ps_monthly_income == "7"){echo "selected='true'";}?>>20000以上</option>
				</select></li>
				<li class="li_two"><label>生日：</label> <select name="sel_year">
					<?php
					for($i = 1954; $i < 1997; $i ++) {
						if ($i == $ps_birthday_year) {
							echo "<option class='selectList' value='" . $i . "' selected='true'>" . $i . "年</option>";
						} else {
							echo "<option class='selectList' value='" . $i . "'>" . $i . "年</option>";
						}
					}
					?>
				</select> <select name="sel_month" class="date_w">
				<?php
				for($i = 1; $i < 13; $i ++) {
					if ($i == $ps_birthday_month) {
						echo "<option class='selectList' value='" . $i . "' selected='true'>" . $i . "月</option>";
					} else {
						echo "<option class='selectList' value='" . $i . "'>" . $i . "月</option>";
					}
				}
				?>
				</select> <select name="sel_day" class="date_w">
				<?php
				for($i = 1; $i < 32; $i ++) {
					if ($i == $ps_birthday_day) {
						echo "<option class='selectList' value='" . $i . "' selected='true'>" . $i . "日</option>";
					} else {
						echo "<option class='selectList' value='" . $i . "'>" . $i . "日</option>";
					}
				}
				?>
				</select></li>
				<li><label>是否有房：</label> <select id="sel_house" name="have_house">
						<option class="selectList" value="0"
							<?php if($ps_is_house == "0"){echo "selected='true'";}?>>未填写</option>
						<option class="selectList" value="1"
							<?php if($ps_is_house == "1"){echo "selected='true'";}?>>已购房</option>
						<option class="selectList" value="2"
							<?php if($ps_is_house == "2"){echo "selected='true'";}?>>与父母同住</option>
						<option class="selectList" value="3"
							<?php if($ps_is_house == "3"){echo "selected='true'";}?>>租房</option>
						<option class="selectList" value="4"
							<?php if($ps_is_house == "4"){echo "selected='true'";}?>>其他</option>
				</select></li>
				<li class="li_two"><label>居住城市：</label> <select id="s_province"
					name="s_province"></select> <select id="s_city" name="s_city"></select>
					<select id="s_county" name="s_county"></select> <script
						class="resources library" src="./Resource/Style/area.js"
						type="text/javascript"></script> <script type="text/javascript">_init_area(<?php echo "'$ps_apartment_str[0]','$ps_apartment_str[1]','$ps_apartment_str[2]'";?>);</script></li>
			</ol>
			<div class="keep">
				<input type="submit" name="user_submit" value="保存" />
			</div>
		</div>
	</form>
</body>
</html>